#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_set>
#include<bits/stdc++.h>
#define fi first
#define se second
#define SIZE(x) ((int)x.size())
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define MP(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
#define VI vector<int>
#define VVI vector< vector<int> >
#define PI pair<int,int>
#define PL pair<ll,ll>


inline int lson(int x){return x<<1;}
inline int rson(int x){return (x<<1)|1;}

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

template<typename T> 
inline void read(T &x){
	x=0;T f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}


//#define INF 5340172838076674L
#define INF 1000000000
#define MOD (100000000-3)
struct node{
	int a,b;
	bool operator<(const node& x)const{
		return a>x.a;
	};
};

struct no3{
	int a,b,c;
	bool operator<(const no3& x)const{
		if(a!=x.a)return a>x.a;
		else return b>x.b;
	}
};

vector<int> edg[500005];
bool sig[500005];
int dep[500005];
int n,w,m;
int st[25][500005];

void dfs(int ind,int d,int fa){
	sig[ind]=true;
	dep[ind]=d;
	st[0][ind]=fa;
	for(auto i:edg[ind]){
		if(sig[i]==false)dfs(i,d+1,ind);
	}
	sig[ind]=false;
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	int sub=dep[x]-dep[y];
	for(int i=0;i<=w;i++){
		if(sub&(1<<i))x=st[i][x];
	}
    if(x==y)return x;
	for(int i=w;i>=0;i--){
		if(st[i][x]!=st[i][y]){
			x=st[i][x];y=st[i][y];
		}
	}
	return st[0][x];
}
int main(){
    #ifdef BUG
    freopen("a.in","r",stdin);
    #endif
    int s;
	n=read();m=read();s=read();
	int a,b,c,d;
	for(int i=1;i<n;i++){
		a=read();b=read();
		edg[a].push_back(b);
		edg[b].push_back(a);
	}
	memset(sig,0,sizeof sig);
	dfs(s,0,-1);
	w=0;
	while((1<<w)<n)++w;
	for(int i=1;i<=w;i++)for(int j=1;j<=n;j++){
		if(st[i-1][j]!=-1)st[i][j]=st[i-1][st[i-1][j]];
		else st[i][j]=-1;
	}
	for(int i=0;i<m;i++){
		a=read();b=read();
        printf("%d\n",lca(a,b));
	}
	return 0;
}